/**
 * Description: 写入到有名管道中
 * File: fifo.c |Time: 2021-04-06 16:07
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


int main(int argc, char *argv[])
{
    if (mkfifo("fifo", 0664)) {
        perror("mkfifo");
        return -1;
    }

    int fd = open("fifo", O_WRONLY);

    char buf[100];

    while(1) {
        printf("input to fifo: ");
        fgets(buf, 100, stdin);

        write(fd, buf, sizeof(buf));

        printf("write finish.\n");
    }

    return 0;
}
